技术经验 • dingxiao • 阅读数:2240 • 2018年7月16日 15:36
//capture, filter, then publish
def capture():
cap = cv2.VideoCapture(VIDEO_ID)
ret,img = cap.read()
img = cv2.convertScaleAbs(img)
try:
for filter_ in FILTERS:
for func in filter_.keys():
args = filter_[func]
img = globals()[func](img,args)
encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), 100]
result,encimg = cv2.imencode('.jpg', img, encode_param)
client.publish('image', base64.b64encode(encimg), qos=0, retain=False)
except Exception:
traceback.print_exc()
JavaScript - Mqtt Sending and Reciving Image
function onMessageArrived(r_message){
console.log(r_message);
document.getElementById("ItemPreview").src = "data:image/png;base64," + convert(r_message.payloadBytes);
}
function convert(buffer) {
var binary = '';
var bytes = new Uint8Array(buffer);
var len = bytes.byteLength;
for (var i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i]);
}
return window.btoa(binary);
}
How to convert image into base64 string using javascript
Receiving image through websocket
Eclipse Paho JavaScript Client
Error when try send a file (image)
How can I publish and subscribe a image file using Mosquitto in python?